using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class InventoryItemClick : MonoBehaviour, IPointerClickHandler
{
  
    public float Interval = 0.5f;
    private float firstLeftClicked = 0;
    private float secondFirstClicked = 0;

    private InventoryItem inventoryItem;
    private ItemGrid itemGrid;

    private void Awake()
    {
        inventoryItem = GetComponent<InventoryItem>();
        itemGrid = inventoryItem.lastItemGrid;
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left) {
            secondFirstClicked = Time.realtimeSinceStartup;
            if (secondFirstClicked - firstLeftClicked < Interval)
            {
                Debug.Log("aaaaaaaaaaaaaa");
            }
            else
            {
                firstLeftClicked = secondFirstClicked;
                InventoryItem clickItem = inventoryItem;
                string name = clickItem.itemData.productName;
                int price = clickItem.itemData.price;
                string describe = clickItem.itemData.describe;

                GameObject allText = GameObject.FindGameObjectWithTag("gridText");
                UnityEngine.Vector2 mousePostion = Input.mousePosition;
                mousePostion = mousePostion - new UnityEngine.Vector2(-60, 50);
                allText.GetComponent<RectTransform>().position = mousePostion;

                Text[] text = allText.GetComponentsInChildren<Text>();
                foreach (Text content in text)
                {
                    if (content.name == "productName")
                    {
                        content.text = name;
                    }
                    if (content.name == "productDetail")
                    {
                        content.text = describe;
                    }
                    if (content.name == "productPrice")
                    {
                        content.text = price + "";
                    }
                }
            }
        }
        
    }
}
